<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text" id="txt">
<button id="but">获取验证码</button>
</body>
<script>
     var btn= document.getElementById("but");
     var time
     btn.onclick=function () {
         var count=5;
         btn.innerHTML="请等待"+count+"秒";
         btn.disabled=true;
         time=setInterval(yan,1000);
         function yan() {
             if (count>1){
                 count--
                 btn.innerHTML="请等待"+count+"秒";
                 btn.disabled=true;
             }else {
                 clearInterval(time);
                 btn.innerHTML="请重新获取验证码"
                 btn.disabled=false;
                 count=5;
             }
         }
     }
</script>
</html>